package cn.lastcc.toolsCollection.common;

import java.awt.Dialog;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * 通用关闭窗口
 * @author bx
 * @version 12.5.5.1
 *
 */
public class WindowCloseing extends WindowAdapter {

	Frame frame = null;
	Dialog dialog = null;
	boolean exit;

	@Override
	public void windowClosing(WindowEvent e) {
		if(this.frame != null)
			this.frame.dispose();
		if(this.dialog != null)
			this.dialog.dispose();
		if(this.exit)
			System.exit(0);
	}

	/**
	 * 通用关闭窗口
	 * @param frame 需要关闭的窗口对象
	 * @param exit 关闭窗口后是否退出整个应用程序
	 */
	public WindowCloseing(Frame frame, boolean exit) {
		this.frame = frame;
		this.exit = exit;
	}

	/**
	 * 通用关闭对话框
	 * @param frame 需要关闭的窗口对象
	 * @param exit 关闭窗口后是否退出整个应用程序
	 */
	public WindowCloseing(Dialog dialog, boolean exit) {
		this.dialog = dialog;
		this.exit = exit;
	}

}
